@pexip/peer-connection
Enumerations
Interfaces
- Bandwidth
- BasePeerConnection
- CorePeerConnectionSignals
- DataChannelConfig
- DataChannelInit
- ExtendedRTCPeerConnection
- MediaEncodingParameters
- PeerConnection
- PeerConnectionCommandSignals
- PeerConnectionOptions
- PeerConnectionSignals
- PexipMediaLine
- RTCPeerConnectionEventMap
- TransceiverConfig
- TransceiverInit
Type Aliases
DetachFn
Ƭ DetachFn: ReturnType
<Signal
<unknown
>["add"
]>
EventHandler
Ƭ EventHandler: (event
: Event
) => void
Type declaration
▸ (event
): void
Parameters
Name | Type |
---|---|
event | Event |
Returns
void
GetSignalTypeFromInterface
Ƭ GetSignalTypeFromInterface<T
, K
>: T
[K
] extends Signal
<infer S> ? S
: never
Type parameters
Name | Type |
---|---|
T | T |
K | extends keyof T |
LogFn
Ƭ LogFn: <T>(msg
: string
, context?
: T
) => void
Type declaration
▸ <T
>(msg
, context?
): void
Type parameters
Name | Type |
---|---|
T | extends Record <string , unknown > |
Parameters
Name | Type |
---|---|
msg | string |
context? | T |
Returns
void
MainPeerConnection
Ƭ MainPeerConnection: BasePeerConnection
MainPeerConnectionOptions
Ƭ MainPeerConnectionOptions: PeerConnectionOptions
MediaConfig
Ƭ MediaConfig: TransceiverConfig
| DataChannelConfig
MediaDirection
Ƭ MediaDirection: Exclude
<RTCRtpTransceiverDirection
, "stopped"
>
MediaInit
Ƭ MediaInit: TransceiverInit
| DataChannelInit
MediaType
Ƭ MediaType: "application"
| "text"
| "message"
| TransceiverMediaType
Media Types ("media")
They are "audio", "video", "text", "application", and "message"
See
https://www.rfc-editor.org/rfc/rfc4566#section-8.2.1
OnDataChannelEventHandler
Ƭ OnDataChannelEventHandler: (event
: RTCDataChannelEvent
) => void
Type declaration
▸ (event
): void
Parameters
Name | Type |
---|---|
event | RTCDataChannelEvent |
Returns
void
OnIceCandidateHandler
Ƭ OnIceCandidateHandler: (event
: RTCPeerConnectionIceEvent
) => void
Type declaration
▸ (event
): void
Parameters
Name | Type |
---|---|
event | RTCPeerConnectionIceEvent |
Returns
void
OnNegotiationNeededHandler
Ƭ OnNegotiationNeededHandler: () => void
Type declaration
▸ (): void
Returns
void
OnRemoteStreamsEventHandler
Ƭ OnRemoteStreamsEventHandler: (config
: TransceiverConfig
) => void
Type declaration
▸ (config
): void
Parameters
Name | Type |
---|---|
config | TransceiverConfig |
Returns
void
OnSecureCheckCodeHandler
Ƭ OnSecureCheckCodeHandler: (secureCheckCode
: string
) => void
Type declaration
▸ (secureCheckCode
): void
Parameters
Name | Type |
---|---|
secureCheckCode | string |
Returns
void
OnTrackEventHandler
Ƭ OnTrackEventHandler: (event
: RTCTrackEvent
) => void
Type declaration
▸ (event
): void
Parameters
Name | Type |
---|---|
event | RTCTrackEvent |
Returns
void
OnTransceiverChangeHandler
Ƭ OnTransceiverChangeHandler: () => void
Type declaration
▸ (): void
Returns
void
PCOptionalsSignals
Ƭ PCOptionalsSignals: Partial
<PeerConnectionSignals
> & Pick
<PeerConnectionCommandSignals
, "onReceiveIceCandidate"
>
PCRequiredSignals
Ƭ PCRequiredSignals: CorePeerConnectionSignals
& Omit
<PeerConnectionCommandSignals
, "onReceiveIceCandidate"
>
PCSignals
Ƭ PCSignals: PCRequiredSignals
& PCOptionalsSignals
RTCPeerConnectionEventListeners
Ƭ RTCPeerConnectionEventListeners: EventListeners
<RTCPeerConnection
, RTCPeerConnectionEventMap
, keyof RTCPeerConnectionEventMap
>
ReferenceValue
Ƭ ReferenceValue: string
References
Ƭ References: Record
<string
, ReferenceValue
>
TransceiverConfigDirectionTuple
Ƭ TransceiverConfigDirectionTuple: [TransceiverConfig
, (MediaDirection | "send" | "recv")?]
Variables
REQUIRED_SIGNAL_KEYS
• Const
REQUIRED_SIGNAL_KEYS: readonly ["onOfferRequired"
, "onReceiveAnswer"
, "onReceiveOffer"
, "onOffer"
, "onOfferIgnored"
, "onAnswer"
, "onError"
]
Functions
assertTransceiverMediaType
▸ assertTransceiverMediaType(mediaType
): "audio"
| "video"
Parameters
Name | Type |
---|---|
mediaType | unknown |
Returns
"audio"
| "video"
changeTransceiverDirection
▸ changeTransceiverDirection(currentDirection
, intendedDirection?
): MediaDirection
Try to derive the direction from currentDirection
and the intendedDirection
Parameters
Name | Type | Default value |
---|---|---|
currentDirection | RTCRtpTransceiverDirection | undefined |
intendedDirection | MediaDirection | "send" | "recv" | 'send' |
Returns
compareArray
▸ compareArray<T
>(list1
, list2
, predicate
): boolean
Compare 2 Array and using the provided predicate to compare
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
list1 | undefined | T [] |
list2 | undefined | T [] |
predicate | (a : undefined | T , b : undefined | T ) => boolean |
Returns
boolean
compareRecord
▸ compareRecord<T
>(record1
, record2
): boolean
Compare 2 flat records (an object with primitive type) using Object.is comparator
Remarks
No deep comparison
Type parameters
Name | Type |
---|---|
T | extends object |
Parameters
Name | Type |
---|---|
record1 | undefined | T |
record2 | undefined | T |
Returns
boolean
createEventQueue
▸ createEventQueue<T
>(callback
): Object
Create a queue to handle buffering and trigger provided callback
being
called in order.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
callback | (item : T ) => void | The callback being called |
Returns
Object
Name | Type |
---|---|
discard | () => void |
enqueue | (item : T ) => void |
flush | () => T [] |
get buffering() | boolean |
get items() | T [] |
get length() | number |
createGetRefs
▸ createGetRefs(pc
): () => { answerOptions
: undefined
| RTCAnswerOptions
= pc.answerOptions; connectionState
: RTCPeerConnectionState
; iceConnectionState
: RTCIceConnectionState
; iceGatheringState
: RTCIceGatheringState
; module
: undefined
| string
= refs.module; offerOptions
: undefined
| RTCOfferOptions
= pc.offerOptions; references
: References
= refs; signalingState
: RTCSignalingState
}
Parameters
Name | Type |
---|---|
pc | PeerConnection |
Returns
fn
▸ (): Object
Returns
Object
Name | Type |
---|---|
answerOptions | undefined | RTCAnswerOptions |
connectionState | RTCPeerConnectionState |
iceConnectionState | RTCIceConnectionState |
iceGatheringState | RTCIceGatheringState |
module | undefined | string |
offerOptions | undefined | RTCOfferOptions |
references | References |
signalingState | RTCSignalingState |
createMainPeerConnection
▸ createMainPeerConnection(signals
, options?
): MainPeerConnection
Logical layer of the Peer Connection for Call/Main, which connecting Signals
and RTCPeerConnection
events,
See
PCSignals
Parameters
Name | Type | Description |
---|---|---|
signals | PCSignals | Provide the required signals for communication |
options | PeerConnectionOptions | Configuration for the the Peer Connection |
Returns
createMediaConfigs
▸ createMediaConfigs(mediaInits?
, onTransceiverChanged?
): Object
Parameters
Name | Type |
---|---|
mediaInits? | MediaInit [] |
onTransceiverChanged? | OnTransceiverChangeHandler |
Returns
Object
Name | Type |
---|---|
addConfig | (peer : RTCPeerConnection , initOrConfig : DataChannelConfig | DataChannelInit ) => DataChannelConfig (peer : RTCPeerConnection , initOrConfig : TransceiverConfig | TransceiverInit ) => TransceiverConfig |
find | (predicate : (config : TransceiverConfig | DataChannelConfig ) => boolean ) => undefined | TransceiverConfig | DataChannelConfig |
getConfig | (key : RTCRtpTransceiver ) => TransceiverConfig | undefined (key : RTCDataChannel ) => DataChannelConfig | undefined |
get configs() | (TransceiverConfig | DataChannelConfig )[] |
createPCSignal
▸ createPCSignal<T
>(name
, crucial?
): Signal
<T
>
Create a general signal with consistent scoped name
Type parameters
Name | Type |
---|---|
T | undefined |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
name | string | undefined | Signal name |
crucial | boolean | true | Signify if the signal is unmissable. |
Returns
Signal
<T
>
createPCSignals
▸ createPCSignals<K
>(more
, scope?
): Pick
<Signals
, SignalKeys
>
Create and return all required and optional (if specified with more
),
signals for peer connection to work
See
- PCOptionalsSignals
- Signal
The following signals created by default 'onOfferRequired', 'onReceiveAnswer', 'onReceiveOffer', 'onOffer', 'onAnswer', 'onError',
- REQUIRED_SIGNAL_KEYS
Type parameters
Name | Type |
---|---|
K | extends "onReceiveIceCandidate" | keyof PeerConnectionSignals |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
more | K [] | undefined | Keys from PCOptionalsSignals , |
scope | string | '' | any scope prefix for the generated signal name, |
Returns
Pick
<Signals
, SignalKeys
>
createPeerConnection
▸ createPeerConnection(options?
, peerConnection?
): PeerConnection
Wrap RTCPeerConnection with polyfill the old APIs and simplifies the common logics
Parameters
Name | Type | Description |
---|---|---|
options | PeerConnectionOptions | Configuration for the peer connection |
peerConnection? | ExtendedRTCPeerConnection | Inject your own RTCPeerConnection, can be used for testing |
Returns
createRTCPeerConnection
▸ createRTCPeerConnection(options?
, listeners?
, existingPC?
): ExtendedRTCPeerConnection
A wrapper to create a RTCPeerConnection instance and subscribe the events
declared from the provided list of listeners
.
Parameters
Name | Type | Description |
---|---|---|
options? | RTCConfiguration | The configuration for the RTCPeerConnection |
listeners? | RTCPeerConnectionEventListeners | A list of listeners to listen on the Peer Connection events |
existingPC? | RTCPeerConnection | Instead of creating a new Peer Connection, it always uses this instance instead. |
Returns
createRefsLog
▸ createRefsLog(getRefs
): Object
create a logger with reference attached
Parameters
Name | Type | Description |
---|---|---|
getRefs | () => Record <string , unknown > | A function to the references for logging |
Returns
Object
Name | Type |
---|---|
debug | LogFn |
error | LogFn |
info | LogFn |
warn | LogFn |
deriveSendDirectionFromTrack
▸ deriveSendDirectionFromTrack(intendedDirection
, track
): MediaDirection
Parameters
Name | Type |
---|---|
intendedDirection | MediaDirection |
track | undefined | null | MediaStreamTrack |
Returns
getCreateLoopbackConnectionFn
▸ getCreateLoopbackConnectionFn(rtcConnection?
, rtcLoopbackConnection?
, loopbackStream?
): (stream
: MediaStream
) => Promise
<MediaStream
>
workaround to allow echo cancellation in Chromium browsers, due to https://bugs.chromium.org/p/chromium/issues/detail?id=687574.
based on https://dev.to/focusedlabs/echo-cancellation-with-web-audio-api-and-chromium-1f8m and https://gist.github.com/alexciarlillo/4b9f75516f93c10d7b39282d10cd17bc
Parameters
Name | Type |
---|---|
rtcConnection | RTCPeerConnection |
rtcLoopbackConnection | RTCPeerConnection |
loopbackStream | MediaStream |
Returns
fn
▸ (stream
): Promise
<MediaStream
>
Parameters
Name | Type |
---|---|
stream | MediaStream |
Returns
Promise
<MediaStream
>
getPeerConnectionStates
▸ getPeerConnectionStates(pc
): Object
Get the states from RTCPeerConnection
Parameters
Name | Type | Description |
---|---|---|
pc | ExtendedRTCPeerConnection | PeerConnection | the peer connection to get the states |
Returns
Object
Name | Type |
---|---|
get connectionState() | RTCPeerConnectionState |
get iceConnectionState() | RTCIceConnectionState |
get iceGatheringState() | RTCIceGatheringState |
get signalingState() | RTCSignalingState |
getRelativeDirection
▸ getRelativeDirection(remoteDirection
): MediaDirection
Get the relative direction so you can get the correct direction, e.g.
"sendonly" <--> "recvonly"
From https://www.rfc-editor.org/rfc/rfc3264.html#section-6.1 > If a stream is offered as sendonly, the corresponding stream MUST be > marked as recvonly or inactive in the answer. If a media stream is > listed as recvonly in the offer, the answer MUST be marked as > sendonly or inactive in the answer. If an offered media stream is > listed as sendrecv (or if there is no direction attribute at the > media or session level, in which case the stream is sendrecv by > default), the corresponding stream in the answer MAY be marked as > sendonly, recvonly, sendrecv, or inactive. If an offered media > stream is listed as inactive, it MUST be marked as inactive in the > answer.
Parameters
Name | Type |
---|---|
remoteDirection | undefined | MediaDirection |
Returns
getStatesAndProps
▸ getStatesAndProps(pc
): Object
Get common states and props from PeerConnection
Parameters
Name | Type | Description |
---|---|---|
pc | PeerConnection | The peer connection to get the info |
Returns
Object
Name | Type |
---|---|
answerOptions | undefined | RTCAnswerOptions |
connectionState | RTCPeerConnectionState |
iceConnectionState | RTCIceConnectionState |
iceGatheringState | RTCIceGatheringState |
offerOptions | undefined | RTCOfferOptions |
signalingState | RTCSignalingState |
isDataChannelConfig
▸ isDataChannelConfig(t
): t is DataChannelConfig
Parameters
Name | Type |
---|---|
t | unknown |
Returns
t is DataChannelConfig
isDataChannelInit
▸ isDataChannelInit(t
): t is DataChannelInit
Parameters
Name | Type |
---|---|
t | unknown |
Returns
t is DataChannelInit
isMediaConfig
▸ isMediaConfig(t
): t is MediaConfig
Parameters
Name | Type |
---|---|
t | unknown |
Returns
t is MediaConfig
isMediaInit
▸ isMediaInit(t
): t is MediaInit
Parameters
Name | Type |
---|---|
t | unknown |
Returns
t is MediaInit
isMediaType
▸ isMediaType(t
): t is "audio" | "video" | "application"
Parameters
Name | Type |
---|---|
t | unknown |
Returns
t is "audio" | "video" | "application"
isSameStream
▸ isSameStream(stream1?
, stream2?
): undefined
| boolean
Compare the provided 2 streams to check if they are the same
Parameters
Name | Type | Description |
---|---|---|
stream1? | MediaStream | the stream to compare |
stream2? | MediaStream | the stream to compare |
Returns
undefined
| boolean
isTransceiverConfig
▸ isTransceiverConfig(t
): t is TransceiverConfig
Parameters
Name | Type |
---|---|
t | unknown |
Returns
t is TransceiverConfig
isTransceiverInit
▸ isTransceiverInit(t
): t is TransceiverInit
Parameters
Name | Type |
---|---|
t | unknown |
Returns
t is TransceiverInit
isTransceiverMediaType
▸ isTransceiverMediaType(mediaType
): mediaType is "audio" | "video"
Parameters
Name | Type |
---|---|
mediaType | unknown |
Returns
mediaType is "audio" | "video"
isTransceiverObsolete
▸ isTransceiverObsolete(transceiver
): boolean
Parameters
Name | Type |
---|---|
transceiver | RTCRtpTransceiver |
Returns
boolean
logReferences
▸ logReferences(refs
): Object
Parameters
Name | Type |
---|---|
refs | References |
Returns
Object
Name | Type |
---|---|
module | undefined | string |
references | References |
merge
▸ merge<T
>(oldParam
, newParam
): RTCRtpEncodingParameters
[]
Merge two array and overwriting the old on with the new one in order
Type parameters
Name | Type |
---|---|
T | extends object [] |
Parameters
Name | Type |
---|---|
oldParam | T |
newParam | T |
Returns
RTCRtpEncodingParameters
[]
resolveKindOrTrack
▸ resolveKindOrTrack(kindOrTrack
): Pick
<TransceiverConfig
, "track"
| "kind"
>
Parameters
Name | Type |
---|---|
kindOrTrack | undefined | "audio" | "video" | MediaStreamTrack |
Returns
Pick
<TransceiverConfig
, "track"
| "kind"
>
setLogger
▸ setLogger(newLogger
): void
Parameters
Name | Type |
---|---|
newLogger | Logger |
Returns
void
subscribePCEvents
▸ subscribePCEvents(pc
, listeners
): void
Parameters
Name | Type |
---|---|
pc | RTCPeerConnection |
listeners | RTCPeerConnectionEventListeners |
Returns
void
wirePeerConnectionEventHandler
▸ wirePeerConnectionEventHandler<T
>(wireOptions
): void
Wire the peer connection event with the pre-defined handler and signal accordingly
Type parameters
Name | Type |
---|---|
T | extends keyof PeerConnectionSignals |
Parameters
Name | Type | Description |
---|---|---|
wireOptions | Object | Wire event params + key - event key + pc - peer connection + signal - the signal to wire |
wireOptions.key | T | - |
wireOptions.pc | PeerConnection | - |
wireOptions.signal | PeerConnectionSignals [T ] | - |
Returns
void
wirePeerConnectionEvents
▸ wirePeerConnectionEvents(pc
, signals
): void
Wire the peer connection events with provided signals
Parameters
Name | Type | Description |
---|---|---|
pc | PeerConnection | peer connection |
signals | Partial <PeerConnectionSignals > | the set of signals to wire |
Returns
void
withSignals
▸ withSignals(peer
): (signals
: Omit
<PCSignals
, "onOfferRequired"
>) => Detach
[]
Handle some core signals for the peer connection.
Parameters
Name | Type | Description |
---|---|---|
peer | PeerConnection | The peer connection |
Returns
fn
the signal subscriptions which are needed to be called when closing the peer connection
▸ (signals
): Detach
[]
Map signals
Parameters
Name | Type | Description |
---|---|---|
signals | Omit <PCSignals , "onOfferRequired" > | The provided signals to map to the PC events |
Returns
Detach
[]